|
RAIS
3.2
|
00001 00028 using System; 00029 using System.Collections.Generic; 00030 using System.Configuration; 00031 using System.Net.Mail; 00032 using System.Text; 00033 00034 namespace RAIS.Common.UserManagement 00035 { 00036 public class AccountRequestAnswer 00037 { 00038 //********************************************************************* 00039 #region Fields 00040 static string smtpServer = ConfigurationManager.AppSettings["SmtpServer"]; 00041 static string emailFrom = ConfigurationManager.AppSettings["AdministratorEmailAccount"]; 00042 static string releaseSubject = "Account request release"; 00043 static string releaseBody = "Your Account request was succesfully released."; 00044 static string rejectSubject = "Account request reject"; 00045 static string rejectBody = "Your Account request was rejected by administrator."; 00046 #endregion Fields 00047 //********************************************************************* 00048 #region Public methods 00049 static public bool SendReleaseMessage(string emailTo, ref string actionResult) 00050 { 00051 return SendEMail(emailTo, releaseSubject, releaseBody, ref actionResult); 00052 } 00053 static public bool SendRejectMessage(string emailTo, ref string actionResult) 00054 { 00055 return SendEMail(emailTo, rejectSubject, rejectBody, ref actionResult); 00056 } 00057 static public bool CheckAdministratorEmailAccountSettings(ref string actionResult) 00058 { 00059 if (string.IsNullOrEmpty(smtpServer) || string.IsNullOrEmpty(emailFrom)) 00060 { 00061 actionResult = RAIS.Common.Messages.EMAIL_SETTINGS_ERROR; 00062 return false; 00063 } 00064 else 00065 return true; 00066 } 00067 #endregion Public methods 00068 //********************************************************************* 00069 #region Private methods 00070 static private bool SendEMail(string emailTo, string subject, string body, ref string actionResult) 00071 { 00072 if (!CheckAdministratorEmailAccountSettings(ref actionResult)) 00073 return false; 00074 00075 try 00076 { 00077 SmtpClient client = new SmtpClient(smtpServer); 00078 //client.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials; 00079 00080 MailMessage message = new MailMessage(emailFrom, emailTo, subject, body); 00081 client.Send(message); 00082 00083 actionResult = string.Format(RAIS.Common.Messages.EMAIL_SENT, emailTo); 00084 return true; 00085 } 00086 catch (Exception ex) 00087 { 00088 actionResult = ex.Message; 00089 return false; 00090 } 00091 } 00092 #endregion Private methods 00093 } 00094 }